import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

import org.apache.shiro.util.Factory;
import org.junit.Test;

public class HelloShiro {

    @Test
    public void shiroLoginTest() {
        // 导入权限ini文件构建权限工厂
        Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
        // 工厂构建安全管理器
        SecurityManager securityManager = factory.getInstance();
        // 使用SecurityUtils工具生效安全管理器
        SecurityUtils.setSecurityManager(securityManager);
        // 使用SecurityUtils工具获得主体
        Subject subject = SecurityUtils.getSubject();
        // 构建账号token
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken("tender", "123");
        // 登录操作
        subject.login(usernamePasswordToken);
        System.out.println("是否登录成功：" + subject.isAuthenticated());
    }

}
